// pages/play/play.js
const db=wx.cloud.database();
const _=db.command;
const playCollection=db.collection('plays');
const newLocal = require('../../data/play3.2');
const danmuList= require('../../data/danmu');
let pinglun=require('../../data/pinglun');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    danmuList,
    danmu:true,
    Reprint_allowed:0,
    isCollect:false,
    height:'auto',
    isDrop:true,
    showNow:newLocal,
    currentId:0,
    playInformation:{},
    pinglunNums:6684,
    pinglun
  },
  danmuon(){
    if(this.data.danmu){
      this.setData({
        danmuList:[],
        danmu:false
      })
    }
    else{
      this.setData({
        danmuList:danmuList,
        danmu:true
      })
    }
  },
  async collectPlay(){
    if(this.data.isCollect){
      this.playInformation.collect--;
      this.setData({
        isCollect:false,
        playInformation:this.playInformation
      });
      playCollection
      .where({
        playid:this.data.playInformation.playid
      })
      .update({
        data:{
          collect:_.inc(-1)
        }
      })
    }
    else{
      this.playInformation.collect++;
      this.setData({
        isCollect:true,
        playInformation:this.playInformation
      })
      playCollection
      .where({
        playid:this.data.playInformation.playid
      })
      .update({
        data:{
          collect:_.inc(1)
        }
      })
    }
  },
  changeDrop(){
    if(this.data.isDrop){
      this.setData({
        height:'0',
        isDrop:false
      })
      }
      else{
        this.setData({
          height:'auto',
          isDrop:true
        })
    }
  },
  changeCurrent(e){
    console.log(e);
    let currentId=e.currentTarget.dataset.current;
    this.setData({
      currentId
    })
    console.log(this.data.currentId !=0 )
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
      const {id}=options;
      const {data:[playInformation]} = await playCollection.where({
        playid:id
      }).get();
      this.playInformation=playInformation;
      // console.log(playInformation);
      this.setData({
        playInformation
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return{
    title:this.data.playInformation.title,
    imageUrl:this.data.playInformation.video_cover,
    path:"/pages/play/play?id="+this.data.playInformation.playid
    }
  }
})